package com.lm.service;

import com.lm.dao.UserDao;
import com.lm.domain.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * mvc
 *
 * @author liming
 * @date 2017/1/15
 */

@Transactional(rollbackFor = Exception.class)
@Service("userService")
public class UserService {

    @Autowired
    private UserDao userDao;

    public List<User> getAll(){
        return userDao.findAll();
    }

    public User getUserById(int userId) {
        return userDao.selectByPrimaryKey(userId);
    }

    public int insert(User user) {
        return userDao.insert(user);
    }

    public int delete(Integer id){
        return userDao.deleteByPrimaryKey(id);
    }

    public int update(User user){
        return userDao.updateByPrimaryKey(user);
    }
}
